﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HVAC.AuxiliaryCurve
{
	public partial class FormDrawAuxiliaryCurve : System.Windows.Forms.Form
	{
		public FormDrawAuxiliaryCurve(ExternalCommandData CmdArgu)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			this.InitialPanelInfo();
			this.m_Cmd = CmdArgu;
		}

		private void frameSel_CheckedChanged(object sender, EventArgs e)
		{
			if (this.frameSel.Checked)
			{
				this.nBoostPointType = 0;
				this.nSelType = 0;
				this.pointSel.Checked = false;
				this.roomSel.Checked = false;
				this.rdoHAngle.Checked = false;
				this.workPlaneRadio.Checked = false;
				this.CurveTypeRadioEnable(true);
			}
			if (this.pointSel.Checked)
			{
				this.nBoostPointType = 1;
				this.nSelType = 0;
				this.frameSel.Checked = false;
				this.roomSel.Checked = false;
				this.rdoHAngle.Checked = false;
				this.workPlaneRadio.Checked = false;
				this.CurveTypeRadioEnable(true);
			}
			if (this.roomSel.Checked)
			{
				this.nBoostPointType = 2;
				this.nSelType = 0;
				this.frameSel.Checked = false;
				this.pointSel.Checked = false;
				this.rdoHAngle.Checked = false;
				this.workPlaneRadio.Checked = false;
				this.CurveTypeRadioEnable(true);
			}
			if (this.rdoHAngle.Checked)
			{
				this.nBoostPointType = 3;
				this.nSelType = 1;
				this.frameSel.Checked = false;
				this.pointSel.Checked = false;
				this.roomSel.Checked = false;
				this.workPlaneRadio.Checked = false;
				this.CurveTypeRadioEnable(true);
			}
			if (this.workPlaneRadio.Checked)
			{
				this.nBoostPointType = 4;
				this.rdoHAngle.Checked = false;
				this.frameSel.Checked = false;
				this.pointSel.Checked = false;
				this.roomSel.Checked = false;
				this.CurveTypeRadioEnable(false);
			}
		}

		private void btnDraw_Click(object sender, EventArgs e)
		{
			if (this.workPlaneRadio.Checked)
			{
				if (this.disLimit.Checked)
				{
					this.m_Type = AuxiliaryCurveType.eModelLineDis;
				}
				else
				{
					this.m_Type = AuxiliaryCurveType.eModelLineNumber;
				}
			}
			else
			{
				this.m_Type = (AuxiliaryCurveType)(this.nStyle ^ this.nSelType ^ this.nPlaceType);
			}
			if (!(this.m_Cmd.Application.ActiveUIDocument.ActiveView is ViewPlan) && Convert.ToInt16(this.m_Type) < 8)
			{
				YJKMessageBox.Show("当前视图非平面视图,无法绘制详图线,请重新选择或转换视图。");
				return;
			}
			this.xSide = Convert.ToDouble(this.txtXSide.Text) / 304.8;
			this.ySide = Convert.ToDouble(this.txtYSide.Text) / 304.8;
			this.xDis = Convert.ToDouble(this.txtXDis.Text) / 304.8;
			this.yDis = Convert.ToDouble(this.txtYDis.Text) / 304.8;
			this.xNumber = Convert.ToInt32(this.txtXNumber.Text);
			this.yNumber = Convert.ToInt32(this.txtYNumber.Text);
			this.SavePanelInfo();
			base.DialogResult = DialogResult.Yes;
		}

		private void btnCancle_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void disLimit_CheckedChanged(object sender, EventArgs e)
		{
			if (this.disLimit.Checked)
			{
				this.nPlaceType = 0;
				this.numberLimit.Checked = false;
				this.DisLimitEnable(true);
				return;
			}
			this.nPlaceType = 2;
			this.DisLimitEnable(false);
		}

		private void numberLimit_CheckedChanged(object sender, EventArgs e)
		{
			if (this.numberLimit.Checked)
			{
				this.nPlaceType = 2;
				this.disLimit.Checked = false;
				this.NumberLimitEnable(true);
				return;
			}
			this.nPlaceType = 0;
			this.NumberLimitEnable(false);
		}

		private void NumberLimitEnable(bool check)
		{
			this.txtXNumber.Enabled = check;
			this.txtYNumber.Enabled = check;
		}

		private void DisLimitEnable(bool check)
		{
			this.txtXDis.Enabled = check;
			this.txtYDis.Enabled = check;
		}

		private void rdoLine_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoLine.Checked)
			{
				this.nStyle = 0;
				this.rdoArc.Checked = false;
				this.refPlane.Checked = false;
				this.CurveTypeRadioEnable(true);
			}
			if (this.rdoArc.Checked)
			{
				this.nStyle = 4;
				this.rdoLine.Checked = false;
				this.refPlane.Checked = false;
				this.CurveTypeRadioEnable(true);
			}
			if (this.refPlane.Checked)
			{
				this.nStyle = 8;
				this.rdoLine.Checked = false;
				this.rdoArc.Checked = false;
				this.CurveTypeRadioEnable(true);
			}
		}

		private void SavePanelInfo()
		{
			UIDataConfig.SaveBoostSetting(new Dictionary<string, int>
			{
				{
					"xDis",
					Convert.ToInt32(this.txtXDis.Text)
				},
				{
					"yDis",
					Convert.ToInt32(this.txtYDis.Text)
				},
				{
					"xSide",
					Convert.ToInt32(this.txtXSide.Text)
				},
				{
					"ySide",
					Convert.ToInt32(this.txtYSide.Text)
				},
				{
					"xNumber",
					Convert.ToInt32(this.txtXNumber.Text)
				},
				{
					"yNumber",
					Convert.ToInt32(this.txtYNumber.Text)
				},
				{
					"nStyle",
					this.nStyle
				},
				{
					"nSelType",
					this.nSelType
				},
				{
					"nPlaceType",
					this.nPlaceType
				},
				{
					"nBoostPointType",
					this.nBoostPointType
				}
			});
		}

		private void InitialPanelInfo()
		{
			foreach (KeyValuePair<string, int> keyValuePair in UIDataConfig.GetBoostSetting())
			{
				string key = keyValuePair.Key;
				uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(key);
				if (num <= 1995386894u)
				{
					if (num <= 71428857u)
					{
						if (num != 32012326u)
						{
							if (num == 71428857u)
							{
								if (key == "xDis")
								{
									this.txtXDis.Text = keyValuePair.Value.ToString();
								}
							}
						}
						else if (key == "xNumber")
						{
							this.txtXNumber.Text = keyValuePair.Value.ToString();
						}
					}
					else if (num != 649382655u)
					{
						if (num == 1995386894u)
						{
							if (key == "nBoostPointType")
							{
								switch (Convert.ToInt32(keyValuePair.Value))
								{
								case 0:
									this.frameSel.Checked = true;
									this.nSelType = 0;
									break;
								case 1:
									this.pointSel.Checked = true;
									this.nSelType = 0;
									break;
								case 2:
									this.roomSel.Checked = true;
									this.nSelType = 0;
									break;
								case 3:
									this.rdoHAngle.Checked = true;
									this.nSelType = 1;
									break;
								case 4:
									this.workPlaneRadio.Checked = true;
									this.CurveTypeRadioEnable(false);
									break;
								}
							}
						}
					}
					else if (key == "ySide")
					{
						this.txtYSide.Text = keyValuePair.Value.ToString();
					}
				}
				else if (num <= 3707603013u)
				{
					if (num != 1998850120u)
					{
						if (num == 3707603013u)
						{
							if (key == "yNumber")
							{
								this.txtYNumber.Text = keyValuePair.Value.ToString();
							}
						}
					}
					else if (key == "nPlaceType")
					{
						int num2 = Convert.ToInt32(keyValuePair.Value);
						if (num2 != 0)
						{
							if (num2 == 2)
							{
								this.numberLimit.Checked = true;
								this.disLimit.Checked = false;
								this.DisLimitEnable(false);
							}
						}
						else
						{
							this.disLimit.Checked = true;
							this.numberLimit.Checked = false;
							this.NumberLimitEnable(false);
						}
					}
				}
				else if (num != 3764836018u)
				{
					if (num != 3905133976u)
					{
						if (num == 3914599612u)
						{
							if (key == "xSide")
							{
								this.txtXSide.Text = keyValuePair.Value.ToString();
							}
						}
					}
					else if (key == "yDis")
					{
						this.txtYDis.Text = keyValuePair.Value.ToString();
					}
				}
				else if (key == "nStyle")
				{
					int num2 = Convert.ToInt32(keyValuePair.Value);
					if (num2 != 0)
					{
						if (num2 != 4)
						{
							if (num2 == 8)
							{
								this.refPlane.Checked = true;
							}
						}
						else
						{
							this.rdoArc.Checked = true;
						}
					}
					else
					{
						this.rdoLine.Checked = true;
					}
				}
			}
		}

		private void CurveTypeRadioEnable(bool enble = false)
		{
			this.rdoArc.Enabled = enble;
			this.rdoLine.Enabled = enble;
			this.refPlane.Enabled = enble;
		}

		public double xSide;

		public double ySide;

		public double xDis;

		public double yDis;

		public int xNumber = 2;

		public int yNumber = 2;

		public int nStyle;

		public int nPlaceType;

		public int nSelType;

		public int nBoostPointType;

		public AuxiliaryCurveType m_Type;

		protected ExternalCommandData m_Cmd;
	}
}
